import { PermissionState } from './state'
import { constantRoutes } from '@/router'
import { AppRouteRecordRaw } from '@/router/types'

export enum PermissionMutationTypes {
  SET_ROUTES = 'SET_ROUTES',
  RESET_ROUTES = 'RESET_ROUTES'
}

export type PermissionMutations<S = PermissionState> = {
  [PermissionMutationTypes.SET_ROUTES](
    state: S,
    routes: AppRouteRecordRaw[]
  ): void
  [PermissionMutationTypes.RESET_ROUTES](
    state: S,
    routes: AppRouteRecordRaw[]
  ): void
}

const mutations: PermissionMutations = {
  [PermissionMutationTypes.SET_ROUTES](state, routes) {
    state.routes = constantRoutes.concat(routes)
    state.dynamicRoutes = routes
  },
  [PermissionMutationTypes.RESET_ROUTES](state, routes) {
    state.routes = []
    state.dynamicRoutes = []
  }
}

export default mutations
